/**
 * @name        hookTime.ts
 * @author      shenyc
 * @date        2020-05-06 - ?
 * @copyright   Copy right (c) shenyc (shenyczz@163.com).
 *              All rights reserved.
 *
 ******************************************************************************/
// {{@@@}}
"use strict"
// ----------------------------------------------------------------------------
export const hookTime = () => {
    const year = ref(1900) // 年份
    const month = ref(1) // 月份
    const day = ref(1) // 天数
    const hour = ref<number | string>(0) // 小时
    const minute = ref<number | string>(0) // 分钟
    const second = ref<number | string>(0) // 秒
    const week = ref("") // 星期
    const nowTime = ref<string>("") // 当前时间

    // 更新时间
    const updateTime = () => {
        const date = new Date()
        year.value = date.getFullYear()
        month.value = date.getMonth() + 1
        day.value = date.getDate()
        hour.value =
            (date.getHours() + "")?.padStart(2, "0") ||
            new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getHours())
        minute.value =
            (date.getMinutes() + "")?.padStart(2, "0") ||
            new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getMinutes())
        second.value =
            (date.getSeconds() + "")?.padStart(2, "0") ||
            new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getSeconds())
        week.value = "日一二三四五六".charAt(date.getDay())
        nowTime.value = `${year.value}年${month.value}月${day.value} ${hour.value}:${minute.value}:${second.value}`
    }

    updateTime()

    return { year, month, day, hour, minute, second, week, nowTime }
}
export default hookTime
// ----------------------------------------------------------------------------
// {{@@@}}
